﻿using System;
class StringLenghtArraySort
{
    static void Main()
    {
        int lenght;
        int minLenght = 1;
        int minIndex = 0;
        string tempStrVar;
        Console.Write("please enter the lenght of array: ");
        while (true)
        {
            try
            {
                lenght = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter lenght:");
            }
        }
        string[] theArray;
        theArray = new string[lenght];
        for (int i = 0; i < lenght; i++)
        {
            Console.Write("please enter {0} element of array: ", i);
            theArray[i] = Console.ReadLine();
        }
        Console.WriteLine("sorted array is:");
        for (int i = 0; i < lenght; i++)
        {
            minLenght = theArray[i].Length;
            for (int j = i; j < lenght; j++)
            {
                if (theArray[j].Length < minLenght)
                {
                    minLenght = theArray[j].Length;
                    minIndex = j;
                }
            }
            if (theArray[i].Length != minLenght)
            {
                tempStrVar = theArray[i];
                theArray[i] = theArray[minIndex];
                theArray[minIndex] = tempStrVar;
            }
        }
        for (int j = 0; j < lenght; j++)
        {
            Console.WriteLine(theArray[j]);
        }
        Console.ReadLine();
    }
}

